package game;


import javax.swing.JOptionPane;

import rps.RPSClient;

public class ingresarNick extends JFrameConFondo {

	public ingresarNick(RPSClient client) {
		gc = client;
		initComponents();
	}

	public ingresarNick() {
		initComponents();
	}

	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jButton2 = new javax.swing.JButton();
		jButton3 = new javax.swing.JButton();
		jPanel1 = new javax.swing.JPanel();
		personaje1 = new javax.swing.JButton();
		personaje2 = new javax.swing.JButton();
		personaje3 = new javax.swing.JButton();
		personaje4 = new javax.swing.JButton();
		seleccionado = new javax.swing.JButton();
		nick = new javax.swing.JLabel();
		jTextField1 = new javax.swing.JTextField();
		guardar = new javax.swing.JButton();
		jButton1 = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("Bowling Net");
		setResizable(false);

		addWindowListener(new java.awt.event.WindowAdapter() {
			public void windowClosing(java.awt.event.WindowEvent evt) {
				formWindowClosing(evt);
			}
		});
		
		jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"imagenes/b5.png"))); // NOI18N
		jButton1.setBorder(null);
		jButton1.setContentAreaFilled(false);
		jButton1.setPressedIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/b5_2.png"))); // NOI18N
		jButton1.setRolloverIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/b5_3.png"))); // NOI18N

		jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"imagenes/b2.png"))); // NOI18N
		jButton2.setBorder(null);
		jButton2.setContentAreaFilled(false);
		jButton2.setPressedIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/b2_3.png"))); // NOI18N
		jButton2.setRolloverIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/b2_2.png"))); // NOI18N

		jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"imagenes/b3.png"))); // NOI18N
		jButton3.setBorder(null);
		jButton3.setContentAreaFilled(false);
		jButton3.setPressedIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/b3_3.png"))); // NOI18N
		jButton3.setRolloverIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/b3_2.png"))); // NOI18N
		jButton3.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton3ActionPerformed(evt);
			}
		});
		jPanel1.setBackground(new java.awt.Color(255, 255, 255));
		jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
		jPanel1.setOpaque(false);
	
		if (personajeSel.equals("imagenes/per1_3.png"))
			personaje1.setIcon(new javax.swing.ImageIcon(getClass()
					.getResource("imagenes/per1_2.png"))); // NOI18N
		else
			personaje1.setIcon(new javax.swing.ImageIcon(getClass()
					.getResource("imagenes/per1.png")));
		personaje1.setBorder(null);
		personaje1.setContentAreaFilled(false);
		personaje1.setRolloverIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/per1_2.png"))); // NOI18N

		if (personajeSel.equals("imagenes/per2_3.png"))
			personaje2.setIcon(new javax.swing.ImageIcon(getClass()
					.getResource("imagenes/per2_2.png"))); // NOI18N
		else
			personaje2.setIcon(new javax.swing.ImageIcon(getClass()
					.getResource("imagenes/per2.png")));
		personaje2.setBorder(null);
		personaje2.setContentAreaFilled(false);
		personaje2.setRolloverIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/per2_2.png"))); // NOI18N
		personaje2.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				personaje2ActionPerformed(evt);
			}
		});

		if (personajeSel.equals("imagenes/per3_3.png"))
			personaje3.setIcon(new javax.swing.ImageIcon(getClass()
					.getResource("imagenes/per3_2.png"))); // NOI18N
		else
			personaje3.setIcon(new javax.swing.ImageIcon(getClass()
					.getResource("imagenes/per3.png")));
		personaje3.setBorder(null);
		personaje3.setContentAreaFilled(false);
		personaje3.setRolloverIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/per3_2.png"))); // NOI18N

		if (personajeSel.equals("imagenes/per4_3.png"))
			personaje4.setIcon(new javax.swing.ImageIcon(getClass()
					.getResource("imagenes/per4_2.png"))); // NOI18N
		else
			personaje4.setIcon(new javax.swing.ImageIcon(getClass()
					.getResource("imagenes/per4.png")));
		personaje4.setBorder(null);
		personaje4.setContentAreaFilled(false);
		personaje4.setRolloverIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/per4_2.png"))); // NOI18N

		seleccionado.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				personajeSel)));
		seleccionado.setBorder(null);
		seleccionado.setContentAreaFilled(false);
		seleccionado.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				seleccionadoActionPerformed(evt);
			}
		});

		nick.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"imagenes/nick.png"))); // NOI18N

		guardar.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"imagenes/b4.png"))); // NOI18N
		guardar.setBorder(null);
		guardar.setBorderPainted(false);
		guardar.setContentAreaFilled(false);
		guardar.setPressedIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/b4_2.png"))); // NOI18N
		guardar.setRolloverIcon(new javax.swing.ImageIcon(getClass()
				.getResource("imagenes/b4_1.png"))); // NOI18N
		guardar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				guardarActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
				jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout
				.setHorizontalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																jPanel1Layout
																		.createSequentialGroup()
																		.addGap(
																				41,
																				41,
																				41)
																		.addGroup(
																				jPanel1Layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								seleccionado,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								170,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addGroup(
																								jPanel1Layout
																										.createSequentialGroup()
																										.addComponent(
																												personaje1,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												59,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addGap(
																												30,
																												30,
																												30)
																										.addComponent(
																												personaje2)
																										.addGap(
																												18,
																												18,
																												18)
																										.addComponent(
																												personaje3,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												86,
																												javax.swing.GroupLayout.PREFERRED_SIZE)))
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				personaje4))
														.addGroup(
																jPanel1Layout
																		.createSequentialGroup()
																		.addGap(
																				93,
																				93,
																				93)
																		.addComponent(
																				nick)
																		.addGap(
																				33,
																				33,
																				33)
																		.addComponent(
																				jTextField1,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				116,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				guardar)))
										.addContainerGap(69, Short.MAX_VALUE)));
		jPanel1Layout
				.setVerticalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								jPanel1Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addComponent(
																personaje2, 0,
																0,
																Short.MAX_VALUE)
														.addComponent(
																personaje3, 0,
																0,
																Short.MAX_VALUE)
														.addComponent(
																personaje4,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																83,
																Short.MAX_VALUE)
														.addComponent(
																personaje1,
																javax.swing.GroupLayout.Alignment.LEADING,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																83,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												seleccionado,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												245,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(39, 39, 39)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(nick)
														.addComponent(guardar)
														.addComponent(
																jTextField1,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(36, 36, 36)));

		personaje1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				personaje1ActionPerformed(evt);
			}
		});
		personaje3.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				personaje3ActionPerformed(evt);
			}
		});
		
		personaje4.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				personaje4ActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup().addGap(21, 21, 21).addGroup(
						layout.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
								.addComponent(jButton3).addComponent(jButton2)
								.addComponent(jButton1)).addPreferredGap(
						javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40,
						Short.MAX_VALUE).addComponent(jPanel1,
						javax.swing.GroupLayout.PREFERRED_SIZE,
						javax.swing.GroupLayout.DEFAULT_SIZE,
						javax.swing.GroupLayout.PREFERRED_SIZE).addGap(88, 88,
						88)));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup().addContainerGap(448,
						Short.MAX_VALUE).addComponent(jButton2,
						javax.swing.GroupLayout.PREFERRED_SIZE, 12,
						javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(
						jButton3).addPreferredGap(
						javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jButton1).addGap(67, 67, 67)).addGroup(
				layout.createSequentialGroup().addGap(84, 84, 84).addComponent(
						jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
						javax.swing.GroupLayout.DEFAULT_SIZE,
						javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(31, Short.MAX_VALUE)));

		jButton2.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton2ActionPerformed(evt);
			}
		});

		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit()
				.getScreenSize();
		setBounds((screenSize.width - 800) / 2, (screenSize.height - 600) / 2,
				800, 600);
	}// </editor-fold>

	// GEN-END:initComponents

	private void seleccionadoActionPerformed(java.awt.event.ActionEvent evt) {

	}

	private void guardarActionPerformed(java.awt.event.ActionEvent evt) {
		if (jTextField1.getText().equals(""))
			JOptionPane.showMessageDialog(null, "Es necesario ingresar el nick");
		else {
			if(jTextField1.getText().length()<=10)
			{
				if (gc == null)
					System.out.println(" viene null");
				else
					System.out.println(" no viene null");
				this.dispose();
				gc.jugar(jTextField1.getText(),personajeSel);
			}
			else
				JOptionPane.showMessageDialog(null, "El  nick debe ser maximo de 10 letras.");
		}
	}

	public static void ingresoNick(final String personaje,
			final RPSClient client) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				personajeSel = personaje;
				JFrameConFondo jf = new ingresarNick(client);
				// jf.setLocationRelativeTo(null);
				jf.setImagen("imagenes/personajes.png");
				jf.setVisible(true);
				jTextField1.requestFocus();
			}
		});
	}

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton guardar;
	private javax.swing.JButton jButton2;

	private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
		i = new instrucciones();
		this.dispose();
		i.mostrarInstrucciones();
	}

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		c = new configuracion();
		this.dispose();
		c.configurarServidor();
	}

	RPSClient gc = null;
	configuracion c;
	instrucciones i;

	private javax.swing.JButton jButton3;
	private javax.swing.JPanel jPanel1;
	static String personajeSel = "";
	private static javax.swing.JTextField jTextField1;
	private javax.swing.JLabel nick;
	private javax.swing.JButton personaje1;
	private javax.swing.JButton jButton1;

	private void personaje1ActionPerformed(java.awt.event.ActionEvent evt) {
		this.dispose();
		this.ingresoNick("imagenes/per1_3.png", gc);
	}

	private javax.swing.JButton personaje2;

	private void personaje2ActionPerformed(java.awt.event.ActionEvent evt) {
		this.dispose();
		this.ingresoNick("imagenes/per2_3.png", gc);
	}

	private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
		r = new records();
		this.dispose();
		//r.mostrarRecords();
		gc.consultRecords();
	}

	records r;
	private javax.swing.JButton personaje3;

	private void personaje3ActionPerformed(java.awt.event.ActionEvent evt) {
		this.dispose();
		this.ingresoNick("imagenes/per3_3.png", gc);
	}

	private javax.swing.JButton personaje4;

	private void personaje4ActionPerformed(java.awt.event.ActionEvent evt) {
		this.dispose();
		this.ingresoNick("imagenes/per4_3.png", gc);
	}

	private void formWindowClosing(java.awt.event.WindowEvent evt) {
		gc.salir();
	}
	
	private javax.swing.JButton seleccionado;
	// End of variables declaration//GEN-END:variables

}
